package top.frsf.reggie.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import top.frsf.reggie.entity.Employee;

import java.time.LocalDateTime;

/**
 * @Author FRSF
 * @Date 2023/1/12 21:51
 * @Description MP自动填充工具类
 */

@Slf4j
@Component
public class CustMetaObjectHandler implements MetaObjectHandler {

    /**
     * @Author: FRSF
     * @Date: 2023/1/12 22:14
     * @Description 插入自动填充
     * @param metaObject: 元数据
     * @return: void
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("MP自动填充 insertFill: {}", metaObject.toString());
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("createUser", BaseContext.getCurrentId());
        metaObject.setValue("updateUser", BaseContext.getCurrentId());
    }


    /**
     * @Author: FRSF
     * @Date: 2023/1/12 22:14
     * @Description 插入或修改自动填充
     * @param metaObject: 元数据
     * @return: void
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("MP自动填充 updateFill: {}", metaObject.toString());
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("updateUser", BaseContext.getCurrentId());
    }
}
